home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / sys / sysStubs.c < prev    next >
C/C++ Source or Header  |  1991-08-09  |  10KB  |  516 lines

  1. /* 
  2.  * sysStubs.c --
  3.  *
  4.  *    Stubs for Unix compatible system calls.
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/sys/RCS/sysStubs.c,v 1.4 91/08/09 14:56:02 shirriff Exp $";
  18. #endif /* not lint */
  19.  
  20. #define MACH_UNIX_COMPAT
  21.  
  22. #include <sprite.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <status.h>
  26. #include <errno.h>
  27. #include <user/sys/types.h>
  28. #include <user/sys/wait.h>
  29. #include <user/sys/time.h>
  30. #include <user/sys/resource.h>
  31. #include <mach.h>
  32. #include <proc.h>
  33. #include <vm.h>
  34. #include <fsutil.h>
  35. #include <assert.h>
  36.  
  37. int debugSysStubs;
  38.  
  39.  
  40. /*
  41.  *----------------------------------------------------------------------
  42.  *
  43.  * Sys_NopStub --
  44.  *
  45.  *      This routine performs a nop.  It is for system calls that
  46.  *    need to exist, but don't need any functionality.
  47.  *
  48.  * Results:
  49.  *      Returns 0.
  50.  *
  51.  * Side effects:
  52.  *      None.
  53.  *
  54.  *
  55.  *----------------------------------------------------------------------
  56.  */
  57. int
  58. Sys_NopStub()
  59. {
  60.     return 0;
  61. }
  62.  
  63. /*
  64.  *----------------------------------------------------------------------
  65.  *
  66.  * Sys_RebootStub --
  67.  *
  68.  *      The stub for the "reboot" Unix system call.
  69.  *
  70.  * Results:
  71.  *      None.
  72.  *
  73.  * Side effects:
  74.  *      Any side effects associated with the call.
  75.  *
  76.  *
  77.  *----------------------------------------------------------------------
  78.  */
  79. /*ARGSUSED*/
  80. int
  81. Sys_RebootStub(howto)
  82.     int howto;
  83. {
  84.     printf("reboot is not implemented.\n");
  85.     Mach_SetErrno(EINVAL);
  86.     return -1;
  87. }
  88.  
  89. #define MAX_HOST_NAME_LEN 255
  90.  
  91. char sysHostName[MAX_HOST_NAME_LEN + 1];
  92. static int sysHostNameLen = 0;
  93. static char sysDomainName[MAX_HOST_NAME_LEN + 1];
  94. static int sysDomainNameLen = 0;
  95. int sysHostID;
  96.  
  97.  
  98. /*
  99.  *----------------------------------------------------------------------
  100.  *
  101.  * Sys_GethostnameStub --
  102.  *
  103.  *      The stub for the "gethostname" Unix system call.
  104.  *
  105.  * Results:
  106.  *      None.
  107.  *
  108.  * Side effects:
  109.  *      Any side effects associated with the call.
  110.  *
  111.  *
  112.  *----------------------------------------------------------------------
  113.  */
  114. int
  115. Sys_GethostnameStub(name, namelen)
  116.     char *name;
  117.     int namelen;
  118. {
  119.     int copyLen;
  120.     ReturnStatus status;
  121.  
  122.     if (debugSysStubs) {
  123.     printf("Sys_GethostnameStub\n");
  124.     }
  125.     if (namelen < sysHostNameLen + 1) {
  126.     copyLen = namelen;
  127.     } else {
  128.     copyLen = sysHostNameLen + 1;
  129.     }
  130.     status = Vm_CopyOut(copyLen, sysHostName, name);
  131.     if (status != SUCCESS) {
  132.     Mach_SetErrno(Compat_MapCode(status));
  133.     return -1;
  134.     }
  135.     return 0;
  136. }
  137.  
  138.  
  139. /*
  140.  *----------------------------------------------------------------------
  141.  *
  142.  * Sys_SethostnameStub --
  143.  *
  144.  *      The stub for the "sethostname" Unix system call.
  145.  *
  146.  * Results:
  147.  *      None.
  148.  *
  149.  * Side effects:
  150.  *      Any side effects associated with the call.
  151.  *
  152.  *
  153.  *----------------------------------------------------------------------
  154.  */
  155. int
  156. Sys_SethostnameStub(name, namelen)
  157.     char *name;
  158.     int namelen;
  159. {
  160.     Proc_ControlBlock    *procPtr = Proc_GetEffectiveProc();
  161.     ReturnStatus    status;
  162.  
  163.     if (debugSysStubs) {
  164.     printf("Sys_SethostnameStub\n");
  165.     }
  166.     if (procPtr->userID!=0) {
  167.     Mach_SetErrno(EPERM);
  168.     return -1;
  169.     }
  170.     if (namelen > MAX_HOST_NAME_LEN) {
  171.     Mach_SetErrno(EINVAL);
  172.     return -1;
  173.     }
  174.     status = Vm_CopyIn(namelen, name, sysHostName);
  175.     if (status != SUCCESS) {
  176.     sysHostNameLen = 0;
  177.     Mach_SetErrno(Compat_MapCode(status));
  178.     return -1;
  179.     }
  180.     sysHostName[namelen] = 0;
  181.     sysHostNameLen = namelen;
  182.     return 0;
  183. }
  184.  
  185.  
  186. /*
  187.  *----------------------------------------------------------------------
  188.  *
  189.  * Sys_GethostidStub --
  190.  *
  191.  *      The stub for the "gethostid" Unix system call.
  192.  *
  193.  * Results:
  194.  *      None.
  195.  *
  196.  * Side effects:
  197.  *      Any side effects associated with the call.
  198.  *
  199.  *
  200.  *----------------------------------------------------------------------
  201.  */
  202. int
  203. Sys_GethostidStub()
  204.  
  205. {
  206.  
  207.     if (debugSysStubs) {
  208.     printf("Sys_GethostidStub\n");
  209.     }
  210.     return sysHostID;
  211. }
  212.  
  213.  
  214. /*
  215.  *----------------------------------------------------------------------
  216.  *
  217.  * Sys_SethostidStub --
  218.  *
  219.  *      The stub for the "sethostid" Unix system call.
  220.  *
  221.  * Results:
  222.  *      None.
  223.  *
  224.  * Side effects:
  225.  *      Any side effects associated with the call.
  226.  *
  227.  *
  228.  *----------------------------------------------------------------------
  229.  */
  230. int
  231. Sys_SethostidStub(hostid)
  232.     int hostid;
  233. {
  234.  
  235.     if (debugSysStubs) {
  236.     printf("Sys_SethostidStub\n");
  237.     }
  238.     sysHostID = hostid;
  239.     return 0;
  240. }
  241.  
  242.  
  243. /*
  244.  *----------------------------------------------------------------------
  245.  *
  246.  * Sys_GetdomainnameStub --
  247.  *
  248.  *      The stub for the "getdomainname" Unix system call.
  249.  *
  250.  * Results:
  251.  *      None.
  252.  *
  253.  * Side effects:
  254.  *      Any side effects associated with the call.
  255.  *
  256.  *
  257.  *----------------------------------------------------------------------
  258.  */
  259. int
  260. Sys_GetdomainnameStub(name, namelen)
  261.     char *name;
  262.     int namelen;
  263. {
  264.     ReturnStatus    status;
  265.     int copyLen;
  266.  
  267.     if (debugSysStubs) {
  268.     printf("Sys_GetdomainnameStub\n");
  269.     }
  270.     if (namelen < sysDomainNameLen + 1) {
  271.     copyLen = namelen;
  272.     } else {
  273.     copyLen = sysDomainNameLen + 1;
  274.     }
  275.     status = Vm_CopyOut(copyLen, sysDomainName, name);
  276.     if (status != SUCCESS) {
  277.     Mach_SetErrno(Compat_MapCode(status));
  278.     return -1;
  279.     }
  280.     return 0;
  281. }
  282.  
  283.  
  284. /*
  285.  *----------------------------------------------------------------------
  286.  *
  287.  * Sys_SetdomainnameStub --
  288.  *
  289.  *      The stub for the "setdomainname" Unix system call.
  290.  *
  291.  * Results:
  292.  *      None.
  293.  *
  294.  * Side effects:
  295.  *      Any side effects associated with the call.
  296.  *
  297.  *
  298.  *----------------------------------------------------------------------
  299.  */
  300. int
  301. Sys_SetdomainnameStub(name, namelen)
  302.     char *name;
  303.     int namelen;
  304. {
  305.     Proc_ControlBlock    *procPtr = Proc_GetEffectiveProc();
  306.     ReturnStatus    status;
  307.  
  308.     if (procPtr->userID!=0) {
  309.     Mach_SetErrno(EPERM);
  310.     return -1;
  311.     }
  312.     if (debugSysStubs) {
  313.     printf("Sys_SetdomainnameStub\n");
  314.     }
  315.     if (namelen > MAX_HOST_NAME_LEN) {
  316.     Mach_SetErrno(EINVAL);
  317.     }
  318.     status = Vm_CopyIn(namelen, name, sysDomainName);
  319.     if (status != SUCCESS) {
  320.     sysDomainNameLen = 0;
  321.     Mach_SetErrno(EFAULT);
  322.     return -1;
  323.     }
  324.     sysDomainName[namelen] = 0;
  325.     sysDomainNameLen = namelen;
  326.     return 0;
  327. }
  328.  
  329.  
  330. /*
  331.  *----------------------------------------------------------------------
  332.  *
  333.  * Sys_ShutdownStub --
  334.  *
  335.  *      The stub for the "shutdown" Unix system call.
  336.  *
  337.  * Results:
  338.  *      None.
  339.  *
  340.  * Side effects:
  341.  *      Any side effects associated with the call.
  342.  *
  343.  *
  344.  *----------------------------------------------------------------------
  345.  */
  346. int
  347. Sys_ShutdownStub()
  348. {
  349.  
  350.     printf("Sys_Shutdown is not implemented\n");
  351.     Mach_SetErrno(EINVAL);
  352.     return -1;
  353. }
  354.  
  355.  
  356. /*
  357.  *----------------------------------------------------------------------
  358.  *
  359.  * Sys_GetpeernameStub --
  360.  *
  361.  *      The stub for the "getpeername" Unix system call.
  362.  *
  363.  * Results:
  364.  *      None.
  365.  *
  366.  * Side effects:
  367.  *      Any side effects associated with the call.
  368.  *
  369.  *
  370.  *----------------------------------------------------------------------
  371.  */
  372. int
  373. Sys_GetpeernameStub()
  374. {
  375.  
  376.     printf("Sys_Getpeername is not implemented\n");
  377.     Mach_SetErrno(EINVAL);
  378.     return -1;
  379. }
  380.  
  381.  
  382. /*
  383.  *----------------------------------------------------------------------
  384.  *
  385.  * Sys_Getrlimit --
  386.  *
  387.  *      The stub for the "getrlimit" Unix system call.
  388.  *    We don't really implement this, so we return INFINITY for
  389.  *    everything except the stack size.  For the stack size, we
  390.  *    return the same as SunOS.
  391.  *
  392.  * Results:
  393.  *      None.
  394.  *
  395.  * Side effects:
  396.  *      Any side effects associated with the call.
  397.  *
  398.  *
  399.  *----------------------------------------------------------------------
  400.  */
  401. #define RLIM_STACK_CUR    0x00200000
  402. #define RLIM_STACK_MAX    0x80000000
  403. int
  404. Sys_GetrlimitStub(resource, rlp)
  405. int resource;
  406. struct rlimit *rlp;
  407. {
  408.  
  409.     struct rlimit rl;
  410.     ReturnStatus status;
  411.  
  412.     if (debugSysStubs) {
  413.     printf("Sys_GethostnameStub(%d, %x)\n", resource, rlp);
  414.     }
  415.     switch (resource) {
  416.     case RLIMIT_CPU:
  417.     case RLIMIT_FSIZE:
  418.     case RLIMIT_DATA:
  419.     case RLIMIT_CORE:
  420.     case RLIMIT_RSS:
  421.         rl.rlim_cur = RLIM_INFINITY;
  422.         rl.rlim_max = RLIM_INFINITY;
  423.     case RLIMIT_STACK:
  424.         rl.rlim_cur = RLIM_STACK_CUR;
  425.         rl.rlim_max = RLIM_STACK_MAX;
  426.         break;
  427.     default:
  428.         Mach_SetErrno(EINVAL);
  429.         return -1;
  430.         break;
  431.     }
  432.     status = Vm_CopyOut(sizeof(struct rlimit), (Address)&rl, (Address)rlp);
  433.     if (status != SUCCESS) {
  434.     Mach_SetErrno(EFAULT);
  435.     return -1;
  436.     }
  437.  
  438.     return 0;
  439. }
  440.  
  441.  
  442. /*
  443.  *----------------------------------------------------------------------
  444.  *
  445.  * Sys_Setrlimit --
  446.  *
  447.  *      The stub for the "setrlimit" Unix system call.
  448.  *
  449.  * Results:
  450.  *      None.
  451.  *
  452.  * Side effects:
  453.  *      Any side effects associated with the call.
  454.  *
  455.  *
  456.  *----------------------------------------------------------------------
  457.  */
  458. int
  459. Sys_SetrlimitStub()
  460. {
  461.  
  462.     printf("Sys_Setrlimit not implemented\n");
  463.     return 0;
  464. }
  465.  
  466.  
  467.  
  468. /*
  469.  *----------------------------------------------------------------------
  470.  *
  471.  * Sys_GetsysinfoStub --
  472.  *
  473.  *      The stub for the "getsysinfo" Unix system call.
  474.  *
  475.  * Results:
  476.  *      None.
  477.  *
  478.  * Side effects:
  479.  *      Any side effects associated with the call.
  480.  *
  481.  *
  482.  *----------------------------------------------------------------------
  483.  */
  484. /*ARGSUSED*/
  485. int
  486. Sys_GetsysinfoStub(op, buffer, nbytes, start, arg)
  487.  
  488.     unsigned  op;
  489.     char      *buffer;
  490.     unsigned   nbytes;
  491.     int       *start;
  492.     char       *arg;
  493. {
  494. #ifdef actually_do_it
  495.     switch (op) {
  496.     case GSI_PROG_ENV:
  497.     case GSI_MAX_UPROCS:
  498.     case GSI_TTYP:
  499.     case GSI_NETBLK:
  500.     case GSI_BOOTDEV:
  501.     case GSI_UACSYS:
  502.     case GSI_UACPARNT:
  503.     case GSI_UACPROC:
  504.     default:
  505.     }
  506. #endif
  507.  
  508.     printf("Sys_getsysinfo not implemented\n");
  509.     /*
  510.      * Just return a 0.  This says that the requested information is
  511.      * not available which is certainly true for the most part.
  512.      */
  513.     return 0;
  514. }
  515.  
  516.